<template>
  <el-dialog title="新增展品分类" :visible.sync="visible" width="30%">
    <el-form :model="form" ref="form">
      <el-form-item label="分类名称" :label-width="formLabelWidth" prop="name" :rules="[rules,rulesLength50]">
        <el-input v-model="form.name" auto-complete="off" placeholder="请输入分类名称"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="confirm('form')">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
  import ApiClient from '@/utils/ApiClient';
  import ValidataRules from '@/utils/validateRules';

  export default {
    name:'AddCategoryDialog',
    props: {
      show: {type: Boolean, default: false},
    },
    data() {
      return {
        formLabelWidth: '80px',
        form: {
          name: '',
        },
        rules: {type:'string',required: true, message: '不能为空', trigger: 'blur'},
        rulesLength50: { validator:ValidataRules.limitMaxLength(50),trigger: 'blur' },
      }
    },
    methods: {
      close() {
        this.$emit('update:show', false)
      },
      //操作
      confirm(form) {
        this.$refs[form].validate((valid) => {
          if (valid) {
            ApiClient.post('/backend/exhibitType/add.do',this.form).then(data => {
              this.$emit('success',1)
              this.close()
            }).catch(data =>{
            })
          } else {
            return false;
          }
        });
      }
    },
    computed: {
      visible: {
        get: function () {
          return this.show == false ? false : true
        },
        set: function () {
          this.$emit('update:show', false)
        }
      }
    },
    mounted() {
    }
  }
</script>
<style>
  .el-dialog__header{
    text-align: center;
  }

</style>
